/*
 * Composer.java
 *
 * Created on 30. Juli 2008, 16:18
 */
package org.nViron.client;

import java.awt.Toolkit;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.media.opengl.GLAutoDrawable;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSlider;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.nViron.Render.GLContext;
import java.awt.Color;
import java.awt.Dialog.ModalExclusionType;
import java.awt.Font;
import org.nViron.Graffiti.GraffitiSource;
import com.sun.opengl.util.Animator;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.swing.AbstractListModel;
import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import org.nViron.Render.RendererGL;
import org.nViron.Tiles.TileSource;
import org.nViron.Tiles.TileSourceGL;
import org.nViron.nvCommon.nvMercator;
import org.nViron.nvCommon.nvPosition;
import org.nViron.nvData.nvDataSource;
import org.nViron.nvMaps.nvMapSource;
import org.nViron.nvParams.nvContextParam;
import org.nViron.nvParams.nvVizParam;
import org.nViron.nvRender.nvRenderer;
import org.nViron.nvSim.nvSimulator;

/**
 *
 * @author cylab
 * @author mbien
 */
public class Composer extends JFrame {

    static {
        // When using a GLCanvas, we have to set the Popup-Menues to be HeavyWeight,
        // so they display properly on top of the GLCanvas
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    }
    private nvDataSource dataSource;
    private nvSimulator simulator;
    private nvMapSource mapSource;
    private nvRenderer renderer;
    private Config config;
    private Animator animator;
    private boolean isFullscreen;

    /** Creates new form MainFrame */
    public Composer() {

        setUndecorated(true);
        setVisible(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        initComponents();
        setTitle("nViron");

        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int width = screen.width * 3 / 4;
        int height = screen.height * 3 / 4;
        setBounds((screen.width - width) / 2, (screen.height - height) / 2, width, height);

        OpenGLCanvas.addGLEventListener(new GLContext(this));
        animator = new Animator(OpenGLCanvas);
        animator.setRunAsFastAsPossible(false);

        // This is a workaround for the GLCanvas not adjusting its size, when the frame is resized.
        OpenGLCanvas.setMinimumSize(new Dimension());

        this.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                // Run this on another thread than the AWT event queue to
                // make sure the call to Animator.stop() completes before
                // exiting
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        animator.stop();
                        System.exit(0);
                    }
                }).start();
            }
        });

        initnVirion();

        initGUI();

        setVisible(true);
        setFocusable(true);
        OpenGLCanvas.setFocusable(true);
        OpenGLCanvas.requestFocus();
    }

    private void initGUI() {
        VizParamList.setModel(new DefaultListModel());
        DefaultListModel model = (DefaultListModel) VizParamList.getModel();
        for (int i = 0; i < simulator.getVizParamMgr().getNumVizParams(); i++) {
            model.addElement(simulator.getVizParamMgr().getVizParam(i).getIdentifier());
        }
        VizParamTextArea.setText(simulator.getVizParamMgr().getVizParam(0).getDescription());

        ContextParamList.setModel(new DefaultListModel());
        model = (DefaultListModel) ContextParamList.getModel();
        for (int i = 0; i < simulator.getContextParamMgr().getNumContextParams(); i++) {
            model.addElement(simulator.getContextParamMgr().getContextParam(i).getIdentifier());
        }
        ContextParamTextArea.setText(simulator.getContextParamMgr().getContextParam(0).getDescription());

        /*
        // Create a list that allows adds and removes
        DefaultListModel model = new DefaultListModel();
        JList list = new JList(model);
        // Initialize the list with items
        String[] items = {"A", "B", "C", "D"};
        for (int i=0; i<items.length; i++) {
        model.add(i, items[i]);
        }
        // Append an item
        int pos = list.getModel().getSize();
        model.add(pos, "E");
        // Insert an item at the beginning
        pos = 0;
        model.add(pos, "a");
        // This method replaces an item:
        // Replace the 2nd item
        pos = 1;
        model.set(pos, "b");
        // These methods are used to remove items:
        // Remove the first item
        pos = 0;
        model.remove(pos);
        // Remove the last item
        pos = model.getSize()-1;
        if (pos >= 0) {
        model.remove(pos);
        }
        // Remove all items
        model.clear();
         */

    }

    @Override
    public void setVisible(boolean show) {
        if (!show && animator != null) {
            animator.stop();
        }
        super.setVisible(show);
        if (show && animator != null && !animator.isAnimating()) {
            animator.start();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Background = new JPanel();
        RulePanel = new JPanel();
        RulesLabel = new JLabel();
        ParametersLabel = new JLabel();
        ruleVizParamLabel = new JLabel();
        rulesVIzParamWeight = new JTextField();
        RulesLabel1 = new JLabel();
        rulesSliderViz = new JSlider();
        jSeparator1 = new JSeparator();
        RulesLabel2 = new JLabel();
        rulesContextParamPanel = new JPanel();
        jScrollPane3 = new JScrollPane();
        rulesContextTextArea = new JTextArea();
        rulesRemoveButton = new JButton();
        rulesAddButton = new JButton();
        decayPanel = new JPanel();
        RulesLabel5 = new JLabel();
        rulesContextParamDecay = new JTextField();
        rulesSliderContextDecay = new JSlider();
        RulesLabel4 = new JLabel();
        jPanel1 = new JPanel();
        RulesLabel3 = new JLabel();
        rulesSliderContextWeight = new JSlider();
        rulesContextParamWeight = new JTextField();
        VizParamPanel = new JPanel();
        VizParamLabel = new JLabel();
        VizParamPane = new JScrollPane();
        VizParamList = new JList();
        jScrollPane1 = new JScrollPane();
        VizParamTextArea = new JTextArea();
        ContextParamPanel = new JPanel();
        ContextParamPane = new JScrollPane();
        ContextParamList = new JList();
        ContextParamLabel = new JLabel();
        jScrollPane2 = new JScrollPane();
        ContextParamTextArea = new JTextArea();
        ControlPanel = new JPanel();
        CloseButton = new JButton();
        jTextField1 = new JTextField();
        MaxButton = new JButton();
        NoGUIButton = new JButton();
        openglPanel = new JPanel();
        OpenGLCanvas = new GLCanvas(createGLCapabilites());
        shoutTextField = new JTextField();
        shoutButton = new JButton();
        jLabel1 = new JLabel();
        jMainMenu = new JMenuBar();

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("nViron");
        setBackground(new Color(0, 0, 0));
        setFont(new Font("Calibri", 0, 12));
        setForeground(Color.white);
        setIconImage(Toolkit.getDefaultToolkit().createImage("icons/icon.png"));
        setModalExclusionType(ModalExclusionType.TOOLKIT_EXCLUDE);
        setName("BaseFrame"); // NOI18N

        Background.setBackground(new Color(0, 0, 0));
        Background.setForeground(new Color(240, 240, 240));
        Background.setFont(new Font("Calibri", 0, 12));
        Background.setName("MappingPanel"); // NOI18N
        Background.addKeyListener(new KeyAdapter() {
            public void keyReleased(KeyEvent evt) {
                BackgroundKeyReleased(evt);
            }
            public void keyTyped(KeyEvent evt) {
                BackgroundKeyTyped(evt);
            }
        });

        RulePanel.setBackground(new Color(25, 25, 25));
        RulePanel.setForeground(new Color(240, 240, 240));
        RulePanel.setFont(new Font("Calibri", 0, 12));

        RulesLabel.setBackground(new Color(0, 0, 0));
        RulesLabel.setFont(new Font("Calibri", 0, 12));
        RulesLabel.setForeground(new Color(240, 240, 240));
        RulesLabel.setText("Rules for");

        ParametersLabel.setBackground(new Color(0, 0, 0));
        ParametersLabel.setFont(new Font("Calibri", 0, 12));
        ParametersLabel.setForeground(new Color(240, 240, 240));
        ParametersLabel.setText("Viz Param");

        ruleVizParamLabel.setBackground(new Color(25, 25, 25));
        ruleVizParamLabel.setForeground(new Color(240, 240, 240));
        ruleVizParamLabel.setText("[select]");

        rulesVIzParamWeight.setBackground(new Color(0, 0, 0));
        rulesVIzParamWeight.setEditable(false);
        rulesVIzParamWeight.setFont(new Font("Calibri", 0, 11)); // NOI18N
        rulesVIzParamWeight.setForeground(new Color(240, 240, 240));
        rulesVIzParamWeight.setHorizontalAlignment(JTextField.CENTER);
        rulesVIzParamWeight.setText("1.0");
        rulesVIzParamWeight.setBorder(new LineBorder(new Color(25, 25, 25), 1, true));
        rulesVIzParamWeight.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                rulesVIzParamWeightActionPerformed(evt);
            }
        });

        RulesLabel1.setBackground(new Color(0, 0, 0));
        RulesLabel1.setFont(new Font("Calibri", 0, 12)); // NOI18N
        RulesLabel1.setForeground(new Color(240, 240, 240));
        RulesLabel1.setText("Weight");

        rulesSliderViz.setBackground(new Color(25, 25, 25));

        jSeparator1.setBackground(new Color(120, 120, 120));
        jSeparator1.setForeground(new Color(25, 25, 25));

        RulesLabel2.setBackground(new Color(0, 0, 0));
        RulesLabel2.setFont(new Font("Calibri", 0, 12));
        RulesLabel2.setForeground(new Color(240, 240, 240));
        RulesLabel2.setText("Contributing Context Params:");

        rulesContextParamPanel.setBackground(new Color(25, 25, 25));
        rulesContextParamPanel.setForeground(new Color(240, 240, 240));
        rulesContextParamPanel.setFont(new Font("Calibri", 0, 11));

        rulesContextTextArea.setBackground(new Color(0, 0, 0));
        rulesContextTextArea.setColumns(20);
        rulesContextTextArea.setEditable(false);
        rulesContextTextArea.setForeground(new Color(240, 240, 240));
        rulesContextTextArea.setRows(5);
        rulesContextTextArea.setText("[nothing selected]");
        rulesContextTextArea.setBorder(null);
        jScrollPane3.setViewportView(rulesContextTextArea);

        rulesRemoveButton.setBackground(new Color(25, 25, 25));
        rulesRemoveButton.setText("Remove");
        rulesRemoveButton.setEnabled(false);

        rulesAddButton.setBackground(new Color(25, 25, 25));
        rulesAddButton.setText("Add");
        rulesAddButton.setEnabled(false);

        decayPanel.setBackground(new Color(50, 50, 50));

        RulesLabel5.setBackground(new Color(0, 0, 0));
        RulesLabel5.setFont(new Font("Calibri", 0, 12));
        RulesLabel5.setForeground(new Color(240, 240, 240));
        RulesLabel5.setText("per second");

        rulesContextParamDecay.setBackground(new Color(0, 0, 0));
        rulesContextParamDecay.setEditable(false);
        rulesContextParamDecay.setFont(new Font("Calibri", 0, 11));
        rulesContextParamDecay.setForeground(new Color(240, 240, 240));
        rulesContextParamDecay.setHorizontalAlignment(JTextField.CENTER);
        rulesContextParamDecay.setText("1.0");
        rulesContextParamDecay.setBorder(new LineBorder(new Color(25, 25, 25), 1, true));
        rulesContextParamDecay.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                rulesContextParamDecayActionPerformed(evt);
            }
        });

        rulesSliderContextDecay.setBackground(new Color(50, 50, 50));

        RulesLabel4.setBackground(new Color(0, 0, 0));
        RulesLabel4.setFont(new Font("Calibri", 0, 12));
        RulesLabel4.setForeground(new Color(240, 240, 240));
        RulesLabel4.setText("Decay");

        GroupLayout decayPanelLayout = new GroupLayout(decayPanel);
        decayPanel.setLayout(decayPanelLayout);
        decayPanelLayout.setHorizontalGroup(
            decayPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, decayPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(RulesLabel4)
                .addGroup(decayPanelLayout.createParallelGroup(Alignment.LEADING)
                    .addGroup(decayPanelLayout.createSequentialGroup()
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(rulesSliderContextDecay, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE))
                    .addGroup(decayPanelLayout.createSequentialGroup()
                        .addGap(101, 101, 101)
                        .addComponent(rulesContextParamDecay, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(RulesLabel5, GroupLayout.PREFERRED_SIZE, 68, GroupLayout.PREFERRED_SIZE)))
                .addGap(205, 205, 205))
        );
        decayPanelLayout.setVerticalGroup(
            decayPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(decayPanelLayout.createSequentialGroup()
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(decayPanelLayout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(RulesLabel4)
                    .addComponent(rulesContextParamDecay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(RulesLabel5))
                .addGap(52, 52, 52))
            .addGroup(decayPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rulesSliderContextDecay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBackground(new Color(50, 50, 50));

        RulesLabel3.setBackground(new Color(0, 0, 0));
        RulesLabel3.setFont(new Font("Calibri", 0, 12));
        RulesLabel3.setForeground(new Color(240, 240, 240));
        RulesLabel3.setText("Weight");

        rulesSliderContextWeight.setBackground(new Color(50, 50, 50));

        rulesContextParamWeight.setBackground(new Color(0, 0, 0));
        rulesContextParamWeight.setEditable(false);
        rulesContextParamWeight.setFont(new Font("Calibri", 0, 11));
        rulesContextParamWeight.setForeground(new Color(240, 240, 240));
        rulesContextParamWeight.setHorizontalAlignment(JTextField.CENTER);
        rulesContextParamWeight.setText("1.0");
        rulesContextParamWeight.setBorder(new LineBorder(new Color(25, 25, 25), 1, true));
        rulesContextParamWeight.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                rulesContextParamWeightActionPerformed(evt);
            }
        });

        GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(RulesLabel3)
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(rulesSliderContextWeight, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(102, 102, 102)
                        .addComponent(rulesContextParamWeight, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(rulesSliderContextWeight, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE)
                        .addComponent(RulesLabel3)
                        .addComponent(rulesContextParamWeight, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        GroupLayout rulesContextParamPanelLayout = new GroupLayout(rulesContextParamPanel);
        rulesContextParamPanel.setLayout(rulesContextParamPanelLayout);
        rulesContextParamPanelLayout.setHorizontalGroup(
            rulesContextParamPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(rulesContextParamPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, GroupLayout.DEFAULT_SIZE, 437, Short.MAX_VALUE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addGroup(rulesContextParamPanelLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(rulesAddButton, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
                    .addGroup(rulesContextParamPanelLayout.createSequentialGroup()
                        .addComponent(decayPanel, GroupLayout.PREFERRED_SIZE, 259, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addComponent(rulesRemoveButton, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18))
        );
        rulesContextParamPanelLayout.setVerticalGroup(
            rulesContextParamPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(rulesContextParamPanelLayout.createSequentialGroup()
                .addGroup(rulesContextParamPanelLayout.createParallelGroup(Alignment.TRAILING, false)
                    .addComponent(jPanel1, Alignment.LEADING, 0, 43, Short.MAX_VALUE)
                    .addComponent(decayPanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE))
                .addGap(13, 13, 13)
                .addComponent(rulesAddButton)
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addComponent(rulesRemoveButton)
                .addContainerGap())
            .addComponent(jScrollPane3, GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
        );

        GroupLayout RulePanelLayout = new GroupLayout(RulePanel);
        RulePanel.setLayout(RulePanelLayout);
        RulePanelLayout.setHorizontalGroup(
            RulePanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(RulePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(RulePanelLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(jSeparator1, GroupLayout.DEFAULT_SIZE, 1107, Short.MAX_VALUE)
                    .addGroup(RulePanelLayout.createSequentialGroup()
                        .addComponent(RulesLabel2)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addComponent(rulesContextParamPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(RulePanelLayout.createSequentialGroup()
                        .addComponent(RulesLabel)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(ParametersLabel)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(ruleVizParamLabel, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)
                        .addGap(618, 618, 618)
                        .addComponent(RulesLabel1)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(rulesSliderViz, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(rulesVIzParamWeight, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        RulePanelLayout.setVerticalGroup(
            RulePanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(RulePanelLayout.createSequentialGroup()
                .addGroup(RulePanelLayout.createParallelGroup(Alignment.TRAILING)
                    .addGroup(RulePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(rulesSliderViz, 0, 0, Short.MAX_VALUE))
                    .addGroup(Alignment.LEADING, RulePanelLayout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(RulePanelLayout.createParallelGroup(Alignment.BASELINE)
                            .addComponent(RulesLabel)
                            .addComponent(ParametersLabel)
                            .addComponent(ruleVizParamLabel)
                            .addComponent(RulesLabel1)))
                    .addGroup(Alignment.LEADING, RulePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(rulesVIzParamWeight, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13)
                .addGroup(RulePanelLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(RulesLabel2)
                    .addComponent(rulesContextParamPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        VizParamPanel.setBackground(new Color(25, 25, 25));
        VizParamPanel.setForeground(new Color(240, 240, 240));
        VizParamPanel.setFont(new Font("Calibri", 0, 12));

        VizParamLabel.setBackground(new Color(0, 0, 0));
        VizParamLabel.setFont(new Font("Calibri", 0, 18));
        VizParamLabel.setForeground(new Color(240, 240, 240));
        VizParamLabel.setText("VizParams");

        VizParamPane.setBorder(null);

        VizParamList.setBackground(new Color(25, 25, 25));
        VizParamList.setFont(new Font("Calibri", 0, 12)); // NOI18N
        VizParamList.setForeground(new Color(240, 240, 240));
        VizParamList.setModel(new AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        VizParamList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        VizParamList.setDoubleBuffered(true);
        VizParamList.setSelectionBackground(new Color(100, 100, 100));
        VizParamList.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent evt) {
                VizParamListValueChanged(evt);
            }
        });
        VizParamPane.setViewportView(VizParamList);

        jScrollPane1.setBackground(new Color(0, 0, 0));
        jScrollPane1.setBorder(null);
        jScrollPane1.setForeground(new Color(240, 240, 240));
        jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        VizParamTextArea.setBackground(new Color(25, 25, 25));
        VizParamTextArea.setColumns(20);
        VizParamTextArea.setFont(new Font("Calibri", 0, 12)); // NOI18N
        VizParamTextArea.setForeground(new Color(240, 240, 240));
        VizParamTextArea.setLineWrap(true);
        VizParamTextArea.setRows(5);
        VizParamTextArea.setWrapStyleWord(true);
        jScrollPane1.setViewportView(VizParamTextArea);
        VizParamTextArea.getAccessibleContext().setAccessibleParent(VizParamPanel);

        GroupLayout VizParamPanelLayout = new GroupLayout(VizParamPanel);
        VizParamPanel.setLayout(VizParamPanelLayout);
        VizParamPanelLayout.setHorizontalGroup(
            VizParamPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, VizParamPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(VizParamPanelLayout.createParallelGroup(Alignment.TRAILING)
                    .addComponent(VizParamPane, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                    .addComponent(VizParamLabel, Alignment.LEADING))
                .addContainerGap())
        );
        VizParamPanelLayout.setVerticalGroup(
            VizParamPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(VizParamPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(VizParamLabel)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(VizParamPane, GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        ContextParamPanel.setBackground(new Color(25, 25, 25));
        ContextParamPanel.setForeground(new Color(240, 240, 240));
        ContextParamPanel.setFont(new Font("Calibri", 0, 12));

        ContextParamPane.setBorder(null);

        ContextParamList.setBackground(new Color(25, 25, 25));
        ContextParamList.setFont(new Font("Calibri", 0, 12)); // NOI18N
        ContextParamList.setForeground(new Color(240, 240, 240));
        ContextParamList.setModel(new AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        ContextParamList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        ContextParamList.setDoubleBuffered(true);
        ContextParamList.setSelectionBackground(new Color(100, 100, 100));
        ContextParamList.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent evt) {
                ContextParamListValueChanged(evt);
            }
        });
        ContextParamPane.setViewportView(ContextParamList);

        ContextParamLabel.setBackground(new Color(0, 0, 0));
        ContextParamLabel.setFont(new Font("Calibri", 0, 18));
        ContextParamLabel.setForeground(new Color(240, 240, 240));
        ContextParamLabel.setText("ContextParams");

        jScrollPane2.setBackground(new Color(0, 0, 0));
        jScrollPane2.setBorder(null);
        jScrollPane2.setForeground(new Color(240, 240, 240));
        jScrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        ContextParamTextArea.setBackground(new Color(25, 25, 25));
        ContextParamTextArea.setColumns(20);
        ContextParamTextArea.setFont(new Font("Calibri", 0, 12)); // NOI18N
        ContextParamTextArea.setForeground(new Color(240, 240, 240));
        ContextParamTextArea.setLineWrap(true);
        ContextParamTextArea.setRows(5);
        ContextParamTextArea.setWrapStyleWord(true);
        jScrollPane2.setViewportView(ContextParamTextArea);
        ContextParamTextArea.getAccessibleContext().setAccessibleParent(ContextParamPanel);

        GroupLayout ContextParamPanelLayout = new GroupLayout(ContextParamPanel);
        ContextParamPanel.setLayout(ContextParamPanelLayout);
        ContextParamPanelLayout.setHorizontalGroup(
            ContextParamPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, ContextParamPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ContextParamPanelLayout.createParallelGroup(Alignment.TRAILING)
                    .addComponent(ContextParamPane, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                    .addComponent(ContextParamLabel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, 0, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
        ContextParamPanelLayout.setVerticalGroup(
            ContextParamPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(ContextParamPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ContextParamLabel)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(ContextParamPane, GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        ControlPanel.setBackground(new Color(25, 25, 25));
        ControlPanel.setForeground(new Color(240, 240, 240));

        CloseButton.setBackground(new Color(0, 0, 0));
        CloseButton.setFont(new Font("Calibri", 0, 12)); // NOI18N
        CloseButton.setText("X");
        CloseButton.setActionCommand("Close");
        CloseButton.setBorder(null);
        CloseButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                CloseButtonActionPerformed(evt);
            }
        });

        jTextField1.setBackground(new Color(25, 25, 25));
        jTextField1.setFont(new Font("Calibri", 0, 24));
        jTextField1.setForeground(new Color(240, 240, 240));
        jTextField1.setText("nViron");
        jTextField1.setBorder(null);

        MaxButton.setBackground(new Color(0, 0, 0));
        MaxButton.setFont(new Font("Calibri", 0, 12)); // NOI18N
        MaxButton.setText("^");
        MaxButton.setActionCommand("Close");
        MaxButton.setBorder(null);
        MaxButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                MaxButtonActionPerformed(evt);
            }
        });

        NoGUIButton.setBackground(new Color(0, 0, 0));
        NoGUIButton.setFont(new Font("Calibri", 0, 12));
        NoGUIButton.setText("<>");
        NoGUIButton.setActionCommand("Close");
        NoGUIButton.setBorder(null);
        NoGUIButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                NoGUIButtonActionPerformed(evt);
            }
        });

        GroupLayout ControlPanelLayout = new GroupLayout(ControlPanel);
        ControlPanel.setLayout(ControlPanelLayout);
        ControlPanelLayout.setHorizontalGroup(
            ControlPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(ControlPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED, 952, Short.MAX_VALUE)
                .addComponent(NoGUIButton, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(MaxButton, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(CloseButton, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        ControlPanelLayout.setVerticalGroup(
            ControlPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(ControlPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ControlPanelLayout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(CloseButton, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(MaxButton, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
                    .addComponent(NoGUIButton, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        openglPanel.setBackground(new Color(25, 25, 25));
        openglPanel.setForeground(new Color(240, 240, 240));

        OpenGLCanvas.setFont(new Font("Calibri", 0, 12)); // NOI18N
        OpenGLCanvas.setName("OpenGL Canvas"); // NOI18N
        OpenGLCanvas.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent evt) {
                OpenGLCanvasMouseClicked(evt);
            }
        });
        OpenGLCanvas.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent evt) {
                OpenGLCanvasMouseDragged(evt);
            }
        });
        OpenGLCanvas.addFocusListener(new FocusAdapter() {
            public void focusGained(FocusEvent evt) {
                OpenGLCanvasFocusGained(evt);
            }
            public void focusLost(FocusEvent evt) {
                OpenGLCanvasFocusLost(evt);
            }
        });
        OpenGLCanvas.addKeyListener(new KeyAdapter() {
            public void keyReleased(KeyEvent evt) {
                OpenGLCanvasKeyReleased(evt);
            }
            public void keyTyped(KeyEvent evt) {
                OpenGLCanvasKeyTyped(evt);
            }
        });

        shoutTextField.setBackground(new Color(50, 50, 50));
        shoutTextField.setFont(new Font("Calibri", 0, 11)); // NOI18N
        shoutTextField.setForeground(new Color(240, 240, 240));
        shoutTextField.setBorder(new LineBorder(new Color(25, 25, 25), 3, true));
        shoutTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                shoutTextFieldActionPerformed(evt);
            }
        });

        shoutButton.setBackground(new Color(25, 25, 25));
        shoutButton.setText("Shout!");
        shoutButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                shoutButtonActionPerformed(evt);
            }
        });

        jLabel1.setBackground(new Color(0, 0, 0));
        jLabel1.setFont(new Font("Calibri", 0, 11)); // NOI18N
        jLabel1.setForeground(new Color(240, 240, 240));
        jLabel1.setText("What are you looking for?");

        GroupLayout openglPanelLayout = new GroupLayout(openglPanel);
        openglPanel.setLayout(openglPanelLayout);
        openglPanelLayout.setHorizontalGroup(
            openglPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(openglPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(shoutTextField, GroupLayout.PREFERRED_SIZE, 483, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(shoutButton, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(60, Short.MAX_VALUE))
            .addComponent(OpenGLCanvas, GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE)
        );
        openglPanelLayout.setVerticalGroup(
            openglPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, openglPanelLayout.createSequentialGroup()
                .addComponent(OpenGLCanvas, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addGroup(openglPanelLayout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                    .addComponent(shoutTextField, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)
                    .addComponent(shoutButton, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        GroupLayout BackgroundLayout = new GroupLayout(Background);
        Background.setLayout(BackgroundLayout);
        BackgroundLayout.setHorizontalGroup(
            BackgroundLayout.createParallelGroup(Alignment.LEADING)
            .addComponent(ControlPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(Alignment.TRAILING, BackgroundLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(BackgroundLayout.createParallelGroup(Alignment.TRAILING)
                    .addComponent(RulePanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(BackgroundLayout.createSequentialGroup()
                        .addComponent(VizParamPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(openglPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(ContextParamPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        BackgroundLayout.setVerticalGroup(
            BackgroundLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(BackgroundLayout.createSequentialGroup()
                .addComponent(ControlPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addGroup(BackgroundLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(openglPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(VizParamPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(ContextParamPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(RulePanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jMainMenu.setBorder(null);
        jMainMenu.setDoubleBuffered(true);
        jMainMenu.setFont(new Font("Calibri", 0, 12));
        jMainMenu.setName("Main Menu"); // NOI18N
        setJMenuBar(jMainMenu);

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addComponent(Background, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addComponent(Background, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CloseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_CloseButtonActionPerformed
        dispose();
        System.exit(0);
    }//GEN-LAST:event_CloseButtonActionPerformed

    private void MaxButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_MaxButtonActionPerformed
        setFullscreen(!isFullscreen);
    }//GEN-LAST:event_MaxButtonActionPerformed

    private void NoGUIButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_NoGUIButtonActionPerformed
        if (VizParamPanel.isVisible()) {
            VizParamPanel.setVisible(false);
            ContextParamPanel.setVisible(false);
            RulePanel.setVisible(false);
        } else {
            VizParamPanel.setVisible(true);
            ContextParamPanel.setVisible(true);
            RulePanel.setVisible(true);
        }
        // TODO adjust exact size of opengl canvas when resizing it
    }//GEN-LAST:event_NoGUIButtonActionPerformed

    private void VizParamListValueChanged(ListSelectionEvent evt) {//GEN-FIRST:event_VizParamListValueChanged
        // When the user release the mouse button and completes the selection,
        // getValueIsAdjusting() becomes false
        if (!evt.getValueIsAdjusting()) {
            JList list = (JList) evt.getSource();
            nvVizParam vizParam = simulator.getVizParamMgr().getVizParam(list.getSelectedIndex());
            VizParamTextArea.setText(vizParam.getDescription());
        }
    }//GEN-LAST:event_VizParamListValueChanged

    private void ContextParamListValueChanged(ListSelectionEvent evt) {//GEN-FIRST:event_ContextParamListValueChanged
        // When the user release the mouse button and completes the selection,
        // getValueIsAdjusting() becomes false
        if (!evt.getValueIsAdjusting()) {
            JList list = (JList) evt.getSource();
            nvContextParam contextParam = simulator.getContextParamMgr().getContextParam(list.getSelectedIndex());
            ContextParamTextArea.setText(contextParam.getDescription());
        }
    }//GEN-LAST:event_ContextParamListValueChanged

    private void OpenGLCanvasMouseClicked(MouseEvent evt) {//GEN-FIRST:event_OpenGLCanvasMouseClicked
        OpenGLCanvas.setFocusable(true);
        OpenGLCanvas.requestFocus();
    }//GEN-LAST:event_OpenGLCanvasMouseClicked

    private void OpenGLCanvasMouseDragged(MouseEvent evt) {//GEN-FIRST:event_OpenGLCanvasMouseDragged
    }//GEN-LAST:event_OpenGLCanvasMouseDragged

    private void OpenGLCanvasKeyReleased(KeyEvent evt) {//GEN-FIRST:event_OpenGLCanvasKeyReleased
        float deltaPos = 0.0001f;
        float deltaAlt = 10.0f;
        float deltaFar = 100.0f;
        int mod = evt.getModifiers();
        nvPosition pos = ((evt.getModifiersEx() & mod) == mod ? simulator.getCameraPosition() : simulator.getLookAtPosition());
        switch (evt.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                pos.setLongitude(pos.getLongitude() - deltaPos);
                break;
            case KeyEvent.VK_RIGHT:
                pos.setLongitude(pos.getLongitude() + deltaPos);
                break;
            case KeyEvent.VK_UP:
                pos.setLatitude(pos.getLatitude() + deltaPos);
                break;
            case KeyEvent.VK_DOWN:
                pos.setLatitude(pos.getLatitude() - deltaPos);
                break;
            case KeyEvent.VK_PAGE_UP:
                pos.setAltitude(pos.getAltitude() + deltaAlt);
                break;
            case KeyEvent.VK_PAGE_DOWN:
                pos.setAltitude(pos.getAltitude() - deltaAlt);
                break;
            case KeyEvent.VK_PLUS:
            case KeyEvent.VK_ADD:
                renderer.getFrustum().setFarP(renderer.getFrustum().getFarP() + deltaFar);
                break;
            case KeyEvent.VK_MINUS:
            case KeyEvent.VK_SUBTRACT:
                renderer.getFrustum().setFarP(renderer.getFrustum().getFarP() - deltaFar);
                break;
        }
    }//GEN-LAST:event_OpenGLCanvasKeyReleased

    private void OpenGLCanvasKeyTyped(KeyEvent evt) {//GEN-FIRST:event_OpenGLCanvasKeyTyped
    }//GEN-LAST:event_OpenGLCanvasKeyTyped

    private void BackgroundKeyTyped(KeyEvent evt) {//GEN-FIRST:event_BackgroundKeyTyped
    }//GEN-LAST:event_BackgroundKeyTyped

    private void BackgroundKeyReleased(KeyEvent evt) {//GEN-FIRST:event_BackgroundKeyReleased
    }//GEN-LAST:event_BackgroundKeyReleased

    private void OpenGLCanvasFocusGained(FocusEvent evt) {//GEN-FIRST:event_OpenGLCanvasFocusGained
    }//GEN-LAST:event_OpenGLCanvasFocusGained

    private void OpenGLCanvasFocusLost(FocusEvent evt) {//GEN-FIRST:event_OpenGLCanvasFocusLost
    }//GEN-LAST:event_OpenGLCanvasFocusLost

    private void shoutButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_shoutButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_shoutButtonActionPerformed

    private void shoutTextFieldActionPerformed(ActionEvent evt) {//GEN-FIRST:event_shoutTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_shoutTextFieldActionPerformed

    private void rulesVIzParamWeightActionPerformed(ActionEvent evt) {//GEN-FIRST:event_rulesVIzParamWeightActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rulesVIzParamWeightActionPerformed

    private void rulesContextParamWeightActionPerformed(ActionEvent evt) {//GEN-FIRST:event_rulesContextParamWeightActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rulesContextParamWeightActionPerformed

    private void rulesContextParamDecayActionPerformed(ActionEvent evt) {//GEN-FIRST:event_rulesContextParamDecayActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rulesContextParamDecayActionPerformed

    /**
     * Called from within initComponents().
     * hint: to customize the generated code choose 'Customize Code' in the contextmenu
     * of the selected UI Component you wish to cutomize in design mode.
     * @return Returns customized GLCapabilities.
     */
    private GLCapabilities createGLCapabilites() {

        GLCapabilities capabilities = new GLCapabilities();
        capabilities.setHardwareAccelerated(true);
        capabilities.setDoubleBuffered(true);

        // try to enable 2x anti aliasing - should be supported on most hardware
        capabilities.setNumSamples(2);
        capabilities.setSampleBuffers(true);

        return capabilities;
    }

    private void initnVirion() {

        config = new Config();
        config.loadConfig("/data/config.xml");

        simulator = nvSimulator.getInstance();
        simulator.init(config, new nvMercator());

        // add map first, cause gaffitisource will try to set id in it
        mapSource = new TileSourceGL(simulator);
        if (!mapSource.init()) {
            Debug.out.println("Failed to init Mapclient!");
        }
        simulator.addMapSource(mapSource);

        dataSource = new GraffitiSource(simulator);
        if (!dataSource.init()) {
            Debug.out.println("Failed to init Baseclient");
        }
        simulator.addDataSource(dataSource);


    }

    private void setFullscreen(boolean val) {
        isFullscreen = val;
        if (isFullscreen) {
            setExtendedState(MAXIMIZED_BOTH);
        } else {
            setExtendedState(NORMAL);
        }

    }

    public void onDisplay(GLAutoDrawable drawable) {
        if (renderer == null) {
            renderer = new RendererGL(drawable, simulator);
            renderer.init();
            ((TileSourceGL) mapSource).setRenderer((RendererGL) renderer);
        }

        simulator.update();

        renderer.render();
    }

    public void onReshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        if (renderer == null) {
            renderer = new RendererGL(drawable, simulator);
            renderer.init();
            ((TileSourceGL) mapSource).setRenderer((RendererGL) renderer);
        }

        renderer.onReshape(x, y, width, height);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        // Run this in the AWT event thread to prevent deadlocks and race conditions
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {

                // switch to system l&f for native font rendering etc.
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception ex) {
                    Logger.getLogger(getClass().getName()).log(Level.INFO, "can not enable system look and feel", ex);
                }

                Composer frame = new Composer();
                frame.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JPanel Background;
    private JButton CloseButton;
    private JLabel ContextParamLabel;
    private JList ContextParamList;
    private JScrollPane ContextParamPane;
    private JPanel ContextParamPanel;
    private JTextArea ContextParamTextArea;
    private JPanel ControlPanel;
    private JButton MaxButton;
    private JButton NoGUIButton;
    private GLCanvas OpenGLCanvas;
    private JLabel ParametersLabel;
    private JPanel RulePanel;
    private JLabel RulesLabel;
    private JLabel RulesLabel1;
    private JLabel RulesLabel2;
    private JLabel RulesLabel3;
    private JLabel RulesLabel4;
    private JLabel RulesLabel5;
    private JLabel VizParamLabel;
    private JList VizParamList;
    private JScrollPane VizParamPane;
    private JPanel VizParamPanel;
    private JTextArea VizParamTextArea;
    private JPanel decayPanel;
    private JLabel jLabel1;
    private JMenuBar jMainMenu;
    private JPanel jPanel1;
    private JScrollPane jScrollPane1;
    private JScrollPane jScrollPane2;
    private JScrollPane jScrollPane3;
    private JSeparator jSeparator1;
    private JTextField jTextField1;
    private JPanel openglPanel;
    private JLabel ruleVizParamLabel;
    private JButton rulesAddButton;
    private JTextField rulesContextParamDecay;
    private JPanel rulesContextParamPanel;
    private JTextField rulesContextParamWeight;
    private JTextArea rulesContextTextArea;
    private JButton rulesRemoveButton;
    private JSlider rulesSliderContextDecay;
    private JSlider rulesSliderContextWeight;
    private JSlider rulesSliderViz;
    private JTextField rulesVIzParamWeight;
    private JButton shoutButton;
    private JTextField shoutTextField;
    // End of variables declaration//GEN-END:variables

    public void onDisplayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
        if (renderer == null) {
            renderer = new RendererGL(drawable, simulator);
            renderer.init();
        } else {
            ((RendererGL) renderer).setDrawable(drawable);
        }
        ((TileSourceGL) mapSource).setRenderer((RendererGL) renderer);
    }
}
